package com.yw.atp.util;

import com.yw.atp.model.Apps;
import com.yw.atp.model.Command;
import com.yw.atp.model.Consult;
import com.yw.atp.model.Department;
import com.yw.atp.model.Group;
import com.yw.atp.model.Profession;
import com.yw.atp.model.Staff;
import com.yw.atp.model.Weather;

public class StringUtil {
	
	public static String[] parStr(String str){
		if(isNotNull(str)){
			return str.split(",");
		}
		return null;
	}
	
    public static boolean isNotNull(String str){
    	return str!=null&&!"".equals(str)?true:false;
    }
    
    public static boolean checkID(Integer id){
    	return id!=null&&id.intValue()>0?true:false;
    }
    
    public static boolean checkStaff(Staff staff){
    	if(staff!=null&&isNotNull(staff.getMobile())&&isNotNull(staff.getMobileID())&&isNotNull(staff.getName())){
    		return true;
    	}
    	return false;
    }
    
    public static boolean checkGroup(Group group){
    	if(group!=null&&isNotNull(group.getGroupid())&&isNotNull(group.getGroupname())&&isNotNull(group.getGroupNameEn())&&isNotNull(group.getGroupDes())&&isNotNull(group.getGroupDesEn())&&isNotNull(group.getOrderId())){
    		return true;
    	}
    	return false;
    }
    
    public static boolean checkApps(Apps apps){
    	if(apps!=null&&isNotNull(apps.getAppid())&&isNotNull(apps.getAppName())&&isNotNull(apps.getAppNameEn())&&isNotNull(apps.getApkName())&&isNotNull(apps.getClassName())&&isNotNull(apps.getIconName())&&apps.getGroupid()!=null&&checkID(apps.getGroupid().getId())&&isNotNull(apps.getOrderId())&&isNotNull(apps.getPackageName())){
    		return true;
    	}
    	return false;
    }
    
    public static boolean checkDepartment(Department dep){
    	if(dep!=null&&isNotNull(dep.getName())){
    		return true;
    	}
    	return false;
    }
    
    public static boolean checkProfession(Profession pro){
    	if(pro!=null&&isNotNull(pro.getName())){
    		return true;
    	}
    	return false;
    }
    
    public static boolean checkWeather(Weather we){
    	if(we!=null&&isNotNull(we.getCurrentTypePeriod())&&isNotNull(we.getTem())&&isNotNull(we.getStatusHalf1())&&isNotNull(we.getStatusHalf2())&&isNotNull(we.getStatusHalf3())&&isNotNull(we.getStatusHalf4())){
    		if(isNotNull(we.getStatusPeriod1())&&isNotNull(we.getStatusPeriod2())&&isNotNull(we.getStatusPeriod3())&&isNotNull(we.getStatusPeriod4())&&isNotNull(we.getStatusPeriod5())&&isNotNull(we.getStatusPeriod6())&&isNotNull(we.getStatusPeriod7())&&isNotNull(we.getStatusPeriod8())&&isNotNull(we.getStatusPeriod9())&&isNotNull(we.getStatusPeriod10())&&isNotNull(we.getStatusPeriod11())&&isNotNull(we.getStatusPeriod12())){
    			if(isNotNull(we.getTypeHalf1())&&isNotNull(we.getTypeHalf2())&&isNotNull(we.getTypeHalf3())&&isNotNull(we.getTypeHalf4())){
    				if(isNotNull(we.getTypePeriod1())&&isNotNull(we.getTypePeriod2())&&isNotNull(we.getTypePeriod3())&&isNotNull(we.getTypePeriod4())&&isNotNull(we.getTypePeriod5())&&isNotNull(we.getTypePeriod6())&&isNotNull(we.getTypePeriod7())&&isNotNull(we.getTypePeriod8())&&isNotNull(we.getTypePeriod9())&&isNotNull(we.getTypePeriod10())&&isNotNull(we.getTypePeriod11())&&isNotNull(we.getTypePeriod12())){
    					try{
    						int tem = Integer.valueOf(we.getTem());
    						if(tem>-45&&tem<45){
    							return true;
    						}else{
    							return false;
    						}
    					}catch(Exception ex){
    						return false;
    					}
    				}
    			}
    		}
    	}
    	return false;
    }
    
    public static boolean checkConsult(Consult con){
    	if(con!=null&&isNotNull(con.getContent())){
    		return true;
    	}
    	return false;
    }
    
    public static boolean checkCommand(Command com,String ... strs){
    	if(com!=null&&checkID(com.getId())){
    		if(strs.length==3){
    			if(isNotNull(strs[0])||isNotNull(strs[1])||isNotNull(strs[2])){
    				return true;
    			}else{
    				System.out.println("command update error 未指定接收人");
    			}
    		}else{
    			System.out.println("command update error : str 长度不为3");
    		}
    		return false;
    	}else{
    		if(com!=null&&isNotNull(com.getCommType())&&isNotNull(com.getContent())){
    			if(com.getSender()!=null&&checkID(com.getSender().getId())){
    				if("1".equals(com.getCommType())){
    					if(strs.length==3){
    						if(isNotNull(strs[0])||isNotNull(strs[1])||isNotNull(strs[2])){
    							return true;
    						}
    					}
    				}else{
    					return true;
    				}
    			}
    		}
    	}
    	
    	return false;
    }
}
